<?php
 
//require_once "core/autoloader.php";

	echo "\n\nLoading...\n";
	
	define("INI_FILE", "kohv.ini");
	define("FATAL_ERR_MSG", "Fatal error: ");
	
	define("CONF_KEY_ZF", "zend_framework_path");
	define("CONF_KEY_VER", "version");
	define("CONF_KEY_SQLITE_PATH", "sqlite_path");	
	define("CONF_KEY_TIME_ZONE", "time_zone");
	
	define("CONF_KEY_FS_ROOT_DIR", "fs_root_dir");
	
	define("CONF_KEY_TEXT_EDITOR", "text_editor");
	
	//************************************************************************************************************************
	// INIT start
	$ini_array = @parse_ini_file(INI_FILE) or die(FATAL_ERR_MSG . INI_FILE . " not found!");
	//print_r($ini_array);	
	
	$include_path = @$ini_array[CONF_KEY_ZF] or die(FATAL_ERR_MSG." key '".CONF_KEY_ZF."' not found in " . INI_FILE);
	$ver = @$ini_array[CONF_KEY_VER] or die(FATAL_ERR_MSG." key '".CONF_KEY_VER."' not found in " . INI_FILE);

	$sqlitePath = @$ini_array[CONF_KEY_SQLITE_PATH] or die(FATAL_ERR_MSG." key '".CONF_KEY_SQLITE_PATH."' not found in " . INI_FILE);
	$timezone = @$ini_array[CONF_KEY_TIME_ZONE] or die(FATAL_ERR_MSG." key '".CONF_KEY_TIME_ZONE."' not found in " . INI_FILE);
	
	$root_dir = @$ini_array[CONF_KEY_FS_ROOT_DIR];
	
	$text_editor = @$ini_array[CONF_KEY_TEXT_EDITOR];
	// INIT end
	//************************************************************************************************************************
	
	
	// add library path		
	set_include_path(get_include_path() . PATH_SEPARATOR . $include_path);
	$include_path = getcwd();	
	set_include_path(get_include_path() . PATH_SEPARATOR . $include_path);	
	
	require_once "Zend\Loader\Autoloader.php";
	Zend_Loader_Autoloader::getInstance()->setFallbackAutoloader(true);
	//exit();
	//phpinfo();exit();

	// Set system version
	Core_Registry::write(Enum_RegistryItems::VERSION, $ver);
	echo "\nKohv version: $ver";
	
	// Set OS type
	$os = Core_OS::detectOS();
	Core_Registry::write(Enum_RegistryItems::COMPUTER_OS, $os);	
	echo "\nComputer's OS: $os";
	
	// set the directories
	$root_dir = realpath( getcwd() . '/' . $root_dir );
	echo "\nKohv 'fs' root dir: $root_dir";
	Core_Registry::write(Enum_RegistryItems::FS_ROOT_DIR, $root_dir);
	
	// set editors
	Core_Registry::write(Enum_RegistryItems::TEXT_EDITOR, $text_editor);
	
	
	
	// define the location of the SQLite database file
	$sqlitePath = getcwd(). $sqlitePath;
	Core_Registry::write(Enum_RegistryItems::SQLITE_PATH, $sqlitePath);

	if(date_default_timezone_set($timezone) != true)
	{
		echo "\n\nWARNING! Time zone was set incorrectly!\n\n";
	}

	
	$shell = new Shell_Shell();
	$shell->start(true);
	
